home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / D-G / DA Skeleton 2.0.cpt / MiscRoutines.p < prev   
Text File  |  1990-06-02  |  3KB  |  137 lines

  1. unit MiscRoutines;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Globals;
  7.  
  8. {This function figures out the resource id's for our DA. See Inside Mac}
  9. {for more information on converting resource id's for DA's. "refNum"}
  10. { is set in the open routine and is located in the unit 'Globals'.}
  11.     function rslvid (id: integer): integer;
  12.  
  13. {This gets the screen size. When ever a new port is created, its initial}
  14. {size is equal to the screenBits.bounds. We need to do this since we}
  15. {cannot use QuickDraw globals from drivers.}
  16.     function GetScrSize: Rect;
  17.  
  18. {FlashDItem will flash a button in a dialog. It is intended for when a user}
  19. {presses the return or enter key to exit the dialog.}
  20.     procedure FlashDItem (dp: DialogPtr; item: integer);
  21.  
  22. {UpdateFilter can be used as a filter to ModalDialog. It will automatically}
  23. {put a ring around the default button and update it if it ever get covered}
  24. {up. It captures the return and enter keys as a item 1 hit.}
  25.     function UpdateFilter (theDialog: DialogPtr; var event: EventRecord; var itemHit: integer): Boolean;
  26.  
  27. {CenterWindow will center dialogs or windows on the screen. Horz and}
  28. {Vert specify if the window should be centered horizontally or Verically}
  29.     procedure CenterWindow (win: WindowPtr; Horz, Vert: Boolean);
  30.  
  31. implementation
  32.  
  33. {--------------------------------•--------------------------------}
  34.  
  35.     function rslvid;
  36.         var
  37.             refNum: integer;
  38.  
  39.     begin
  40.         refNum := Abs(-dce^.dCtlRefNum) - 1;
  41.         rslvid := BitOr($C000, BSL(refNum, 5)) + id;
  42.     end;
  43.  
  44. {--------------------------------•--------------------------------}
  45.  
  46.     function GetScrSize;
  47.         var
  48.             aPort: GrafPtr;
  49.     begin
  50.         aPort := GrafPtr(NewPtr(SIZEOF(GrafPort)));
  51.         OpenPort(aPort);
  52.         GetScrSize := aPort^.portBits.bounds;
  53.         ClosePort(aPort);
  54.         DisposPtr(Ptr(aPort));
  55.     end;
  56.  
  57. {--------------------------------•--------------------------------}
  58.  
  59.     procedure FlashDItem;
  60.         var
  61.             tickScratch: longint;
  62.             itype: integer;
  63.             ihan: Handle;
  64.             irect: Rect;
  65.  
  66.     begin
  67.         GetDItem(dp, item, itype, ihan, irect);
  68.         HiliteControl(ControlHandle(ihan), 1);
  69.         Delay(6, tickScratch);
  70.     end;
  71.  
  72. {--------------------------------•--------------------------------}
  73.  
  74.     function UpdateFilter;
  75.         var
  76.             chCode: integer;
  77.             itype: integer;
  78.             ihan: Handle;
  79.             irect: Rect;
  80.  
  81.     begin
  82.         SetUpA4;
  83.  
  84.         UpdateFilter := False;
  85.  
  86.         case event.what of
  87.             keyDown: 
  88.                 begin
  89.                     chCode := BitAnd(event.message, charCodeMask);
  90.                     if (chCode = 13) or (chCode = 3) then
  91.                         begin
  92.                             itemHit := 1;
  93.                             FlashDItem(theDialog, itemHit);
  94.                             UpdateFilter := True;
  95.                         end;
  96.                 end;
  97.             mouseDown: 
  98.                 ;
  99.             UpdateEvt: 
  100.                 begin
  101.                     GetDItem(theDialog, 1, itype, ihan, irect);
  102.                     InsetRect(irect, -4, -4);
  103.                     PenSize(3, 3);
  104.                     FrameRoundRect(irect, 16, 16);
  105.                     PenSize(1, 1);
  106.                 end;
  107.         end;
  108.  
  109.         RestoreA4;
  110.     end;
  111.  
  112. {--------------------------------•--------------------------------}
  113.  
  114.     procedure CenterWindow;
  115.         var
  116.             h, v: integer;
  117.  
  118.     begin
  119.         if (Horz) then
  120.             h := (screenBounds.right - (win^.portRect.right - win^.portRect.left)) div 2
  121.         else
  122.             h := -win^.portBits.bounds.left;
  123.         if (Vert) then
  124.             begin
  125.                 v := (screenBounds.bottom - (win^.portRect.bottom - win^.portRect.top)) div 2;
  126.                 if (screenBounds.bottom > 500) then
  127.                     v := v - 200;
  128.             end
  129.         else
  130.             v := -win^.portBits.bounds.top;
  131.  
  132.         MoveWindow(win, h, v, True);
  133.     end;
  134.  
  135. {--------------------------------•--------------------------------}
  136.  
  137. end.